home *** CD-ROM | disk | FTP | other *** search
/ Windows 98 Secrets / Windows 98 Secrets Gold - Disc 1.iso / tools / textedit / winedit / wwwedit.dl_ / wwwedit.dl
Text File  |  1996-10-25  |  14KB  |  340 lines

  1. ; This is a common WIL script file for the editor.  It is used by both the
  2. ; utility menu in the Professional version and also for some internal
  3. ; editor functions...like looking up keyword help on a mouse click.
  4.  
  5.       CancelCmd="exit"
  6.       goto %param1%
  7.  
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. :BUTTONMACRO
  10. ; we get here via a line like
  11. ; Call("WWWEDIT.DLL", "BUTTONMACRO 1")  Add a goto label to jump to 
  12. ; a specific section
  13. ; e.g.
  14. ;       goto butmac%param2%
  15. ;      :butmac1
  16. ;          code here
  17. ;          return
  18. ;      :butmac2
  19. ;           code here
  20. ;          return
  21.         Message("Sample Macro","You called user macro number %param2%")
  22.         exit
  23.  
  24.  
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  26. :KEYWORDHELP
  27.  
  28. ;First do some initialization and grab the word help is desired for.
  29. ;debug(1)
  30. CancelCmd="goto KWHDONE"      ; Setup cancel processing - clear variables
  31. HelpWord = wEdGetWord()         ; Get Selected word
  32. if HelpWord==""
  33.    Message("WinEdit Help Error","Cursor must be on a word to use this function.")
  34. else
  35.    ; Locate our WEHELP.INI file and determine help file list to process
  36.     WEDir = DirHome()
  37.     inifile = StrCat(WEDir, "HELP\WEHELP.INI")
  38.     if FileExist(inifile)==@FALSE then inifile=FileLocate("WEHELP.INI")
  39.     filext = FileExtension(wGetFileName())
  40.     If filext == "" Then filext = "NONE"   ; section for files w/no extension
  41.     helpsec = IniReadPvt("EXTENSIONS", filext, "DEFAULT", inifile)
  42.     HFnum = 0
  43. ; Get the next help file from the list,
  44.  
  45.     for HFNUM=1 to 1000
  46.        ffound=0
  47.        wehinfo = StrUpper(IniReadPvt(helpsec, "HF%HFnum%", "NONE", inifile))
  48.        If wehinfo == "NONE"
  49.            Message("WinEdit Help Error - %helpword%", "No applicable help files found.")
  50.            break
  51.        endif
  52.        if wehinfo == "" then continue     ; Empty HFx setting, skip
  53.  
  54.        ; Extract and build information from the HFx setting
  55.        hfr2=strindex(wehinfo," ",0,@backscan)
  56.        HelpFileI=strsub(wehinfo,1,hfr2-1) ; Long File Name Fix
  57.        wehfile = StrCat(WEDir, "HELP\",FileRoot(HelpFileI), ".WEH")
  58.        if FileExist(wehfile)==@FALSE then wehfile=FileLocate(StrCat(FileRoot(HelpFileI),".WEH"))
  59.        wehtype=strsub(wehinfo,hfr2+1,-1)
  60.  
  61.        ; Make sure we have a WEH file someplace
  62.  
  63.        If !(FileExist(wehfile))
  64.           Message("WEHELP.INI Error", "%wehfile% not found")
  65.           break
  66.        endif
  67.        
  68.        ; Read Keyword data from WEH file
  69.        wehdata=IniReadPvt("KEYWORDS",helpword,"",wehfile)
  70.        If wehdata == "" Then continue    ; No keyword defined, try next file.
  71.        ;debug(0)
  72.         ffound=1
  73.        ;WEH file located.  See if WEH file contains search hints.
  74.        helpfile2=IniReadPvt("LOOKUP","Located","",wehfile)
  75.        if !FileExist(helpfile2)
  76.          
  77.           HelpFile2=HelpFileI      ; then test actual ini setting
  78.           if !FileExist(HelpFile2)
  79.           ffound=0
  80.           while 1
  81.              if WinMetrics(-2)==2    ; 32 bit platform
  82.                 HintName=IniReadPvt("LOOKUP","ALTLONG","",wehfile)
  83.                 hintreg=IniReadPvt("LOOKUP","REG32","",wehfile)
  84.                 if hintname!="" then gosub hlpsrch
  85.                 if ffound==1 then break
  86.              
  87.                 HintName=IniReadPvt("LOOKUP","ALTSHORT","",wehfile)
  88.                 if hintname!="" then gosub hlpsrch
  89.                 if ffound==1 then break
  90.              endif
  91.           
  92.              HintName=IniReadPvt("LOOKUP","ALTSHORT","",wehfile)
  93.              hintreg=IniReadPvt("LOOKUP","REG16","",wehfile)
  94.              if hintname!="" then gosub hlpsrch
  95.              if ffound==1 then break
  96.              hintname=strcat(FileRoot(HelpFileI),'.',FileExtension(HelpFileI))
  97.              hintreg=""
  98.              gosub hlpsrch
  99.              break
  100.           endwhile ; random searching
  101.           if ffound==0
  102.              ; Give up and ask user....what a concept...
  103.              while 1
  104.                 HelpFile2=HelpFile                        ; ask user
  105.                 CancelCmd="goto HELPCAN23"
  106.                 HelpFile2=AskFileName("Please locate %HelpFile%","","Help Files (*.HLP)|*.HLP|",HelpFile2,1)
  107.                 CancelCmd="exit"
  108.                 ; Verify we can access help file user entered
  109.                 if FileExist(HelpFile2)
  110.                    ffound=1
  111.                    break
  112.                 endif
  113.  
  114.                 ; If cancelled, remove reference to help file from WEHELP.INI
  115.                 :HELPCAN23
  116.                 a=AskYesNo(HelpFile2,"Do you wish to remove %HelpFile% from the help file search?")
  117.                 if a==@YES  then IniWritePvt(helpsec,"HF%HFnum%","",inifile)
  118.                 break
  119.  
  120.              endwhile ;asking user
  121.           endif   ; asking user
  122.        endif   ; raw ini setting
  123.        IniWritePvt("LOOKUP","Located",helpfile2,wehfile)    ; save in weh file for next time
  124.     endif   ; file not located in weh hint
  125.       
  126.       
  127.     if ffound==0 then continue
  128.     break   ; done.  break out of next file for loop
  129.    next   ; next HFx for loop
  130. if ffound==1
  131.         switch wehtype
  132.  
  133.         case 1
  134.               wehdata=strreplace(wehdata,"~",strcat(num2char(13),num2char(10)))
  135.               Message(helpword,wehdata)
  136.               break
  137.  
  138.         case 2
  139.               WinHelp(HelpFile2,"PARTIALKEY",helpword)
  140.               break
  141.  
  142.         case 3
  143.  
  144.               ErrorMode(@OFF)
  145.               RunZoom(HelpFile2,helpword)
  146.               ErrorMode(@CANCEL)
  147.               if LastError()==1902 then Message("WinEdit Help Error","Help for >%helpword%< not available.")
  148.               break
  149.  
  150.         case 100
  151.            ; Put your HelpFileType 100 stuff here
  152.               Message("WinEdit User Help - %HelpFile2%","Help for %helpword% goes here")
  153.               break
  154.        end switch       
  155. endif
  156. endif  ; from initial check for cusror on word         
  157. :KWHDONE
  158. ; Drop variables to save memory space
  159.         Drop(HelpWord,WEDir,inifile,filext,helpsec,HFnumhintreg,hintdir,hintname,ffound)
  160.         Drop(wehinfo,HelpFileI,wehfile,wehtype,wehdata,HelpFile,HelpFile2)
  161.  
  162.         Exit
  163.  
  164. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  165. :HLPSRCH
  166.    hintdir=""
  167.    ErrorMode(@OFF)
  168.    if hintreg!="" then hintdir=RegQueryValue(@RegMachine,hintreg)
  169.    ErrorMode(@CANCEL)
  170.    if hintdir==0 then hintdir=""
  171.    helpfile2= strcat(hintdir,hintname)
  172.    if !FileExist(helpfile2)
  173.       ; First of all, completely ignore path to help file specified and
  174.       ; look in  help directory FIRST!
  175.       HelpFile=hintname
  176.       HelpFile2=strcat(DirHome(),"HELP\%HelpFile%")         ;look in HELP dir first
  177.       if !FileExist(HelpFile2)
  178.          ; Remove directory, and let Windows search path
  179.          HelpFile2=HelpFile                         ; try local dir and path
  180.          if !FileExist(HelpFile2)
  181.             ; Check editor home dir just in case path search bypassed it
  182.             HelpFile2="%WEDir%%HelpFile%"            ; check editor dir
  183.             if !FileExist(HelpFile2) then return
  184.          endif
  185.       endif     
  186.    endif
  187.    ffound=1        
  188. return
  189.  
  190.  
  191.  
  192. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  193.  
  194. :REBUILD
  195. ; Rebuild Macro Menu
  196. ;    
  197. ; This script writes out WinEdit's Macro Menu script.  Each WBT or MAC
  198. ; file that is found in the Macros subdirectory becomes a menu item
  199. ; on the Macro Menu.  You can nest subdirectories of scripts under the 
  200. ; Macros directory and this script will create a popout submenu for
  201. ; that subdirectory.
  202.     
  203. ; You can modify the path variable below to point to a different 
  204. ; location for storing your WIL scripts, but don't change the save location
  205. ; of the menu script, MACRO.MNU.  It needs to be saved in WinEdit's
  206. ; home directory.
  207. CRLF=strcat(num2char(13),num2char(10))
  208. path = strcat(DirHome(),"Macros")     
  209. if !DirExist(path) then DirMake(path)
  210. bufsize = min(16384,FileSize(strcat(DirHome(),"Macro.MNU")) * 2)
  211. menufile = BinaryAlloc(bufsize)
  212. offset = 0
  213. ;menufile = FileOpen(strcat(DirHome(),"Macro.MNU"), "WRITE")
  214.                       
  215. offset = offset + BinaryPokeStr(menufile, offset, strcat(';',CRLF))
  216. offset = offset + BinaryPokeStr(menufile, offset, strcat('; WinEdit Script for Macro Menu',CRLF))
  217. offset = offset + BinaryPokeStr(menufile, offset, strcat(';',CRLF))
  218. offset = offset + BinaryPokeStr(menufile, offset, strcat('; WinEdit records macros as WIL scripts.  After recording a macro,',CRLF))
  219. offset = offset + BinaryPokeStr(menufile, offset, strcat('; save the resulting script in the WinEdit\Macros directory.',CRLF))
  220. offset = offset + BinaryPokeStr(menufile, offset, strcat(';',CRLF))
  221. offset = offset + BinaryPokeStr(menufile, offset, strcat('; The wRecord() macro function will rebuild this script whenever you save ',CRLF))
  222. offset = offset + BinaryPokeStr(menufile, offset, strcat('; a new macro, with the basename of each file used as the menu item.',CRLF))
  223. offset = offset + BinaryPokeStr(menufile, offset, strcat(';',CRLF))
  224. offset = offset + BinaryPokeStr(menufile, offset, strcat('; Macros stored in subdirectories of the WinEdit\Macros directory will',CRLF))
  225. offset = offset + BinaryPokeStr(menufile, offset, strcat('; be shown as popout menus, with the subdirectory name used as the menu name',CRLF))
  226. offset = offset + BinaryPokeStr(menufile, offset, strcat(';',CRLF))
  227. offset = offset + BinaryPokeStr(menufile, offset, strcat('; Advanced users can examine and modify the Rebuild script, which is contained',CRLF))
  228. offset = offset + BinaryPokeStr(menufile, offset, strcat('; in the WWWEDIT.DLL script file stored in the Windows directory.',CRLF))
  229. offset = offset + BinaryPokeStr(menufile, offset, CRLF)
  230. offset = offset + BinaryPokeStr(menufile, offset, CRLF)
  231. offset = offset + BinaryPokeStr(menufile, offset, strcat('Record       \ ^R  ; Start or Stop recording a macro',CRLF))
  232. offset = offset + BinaryPokeStr(menufile, offset, strcat('      wRecord()',CRLF))
  233. offset = offset + BinaryPokeStr(menufile, offset, strcat('',CRLF))
  234. offset = offset + BinaryPokeStr(menufile, offset, strcat('Edit Macro Script   ; Open a Macro Script file for editing',CRLF))
  235. offset = offset + BinaryPokeStr(menufile, offset, strcat('      types="WIL Files|*.wbt;*.mac;*.mnu|"',CRLF))
  236. offset = offset + BinaryPokeStr(menufile, offset, strcat('      filename = AskFileName("Edit Macro Script", strcat(DirHome(),"Macros"), types, "", 1)',CRLF))
  237. offset = offset + BinaryPokeStr(menufile, offset, strcat('      wFileOpen(filename)',CRLF))
  238. offset = offset + BinaryPokeStr(menufile, offset, strcat('      Drop(filename)',CRLF))
  239. offset = offset + BinaryPokeStr(menufile, offset, CRLF)
  240. if (WinVersion(@MAJOR)) >= 4
  241.    offset = offset + BinaryPokeStr(menufile, offset, strcat('Open Macro Menu Folder  ; Directly edit the Macro Menu Folder',CRLF))
  242.    runstring = strcat(DirHome(),"Macros")
  243.    offset = offset + BinaryPokeStr(menufile, offset, strcat('      Run("Start","%runstring%")',CRLF))
  244.    offset = offset + BinaryPokeStr(menufile, offset, CRLF)
  245. endif   
  246. offset = offset + BinaryPokeStr(menufile, offset, strcat('Rebuild Macro Menu  ; Build a menu of scripts in the Macros folder',CRLF))
  247. offset = offset + BinaryPokeStr(menufile, offset, strcat('      call("WWWEDIT.DLL","REBUILD")',CRLF))
  248. offset = offset + BinaryPokeStr(menufile, offset, CRLF)
  249.  
  250. ; process scripts in subdirectories as popout menus, using the
  251. ; directory name as the menu item
  252. DirChange(path)
  253. DirList = DirItemize("*.*")
  254. DirCount = ItemCount(DirList,@Tab)
  255. i = 0;
  256. indent = @TRUE                    
  257. separator = @TRUE
  258. while (i < DirCount)
  259.     DirName = ItemExtract(i+1,DirList,@Tab)
  260.     DirChange(DirName)
  261.     ; check to see if there are any script files
  262.     FileList = FileItemize("*.WBT|*.MAC")
  263.     FileCount = ItemCount(FileList,Tab)
  264.     if FileCount
  265.        if separator
  266.           offset = offset + BinaryPokeStr(menufile,offset, strcat("_%DirName%",CRLF))
  267.        else                 
  268.           offset = offset + BinaryPokeStr(menufile,offset, strcat("%DirName%",CRLF))
  269.        endif
  270.        separator = @FALSE
  271.        gosub DoFiles
  272.     endif
  273.     DirChange(path)
  274.     i = i+1
  275. endwhile
  276. Drop(DirList,DirCount,i)
  277.  
  278. ; then do the files in the Macros directory,
  279. ; each filename becomes a menu item
  280. indent = @FALSE
  281. separator = @TRUE
  282. DirName = ""
  283. gosub DoFiles
  284. BinaryWrite(menufile,strcat(DirHome(),"Macro.MNU"))
  285. BinaryFree(menufile)
  286. Drop(FileList,FileCount,path,menufile,indent,separator,DirName,offset,bufsize,CRLF)
  287. return
  288.       
  289. :DoFiles
  290. FileList = FileItemize("*.WBT|*.MAC")
  291. FileCount = ItemCount(FileList,Tab)
  292. index = 0
  293. total = 1
  294. while (index < FileCount)
  295.     file = ItemExtract(index+1,FileList,Tab)
  296.     name = FileRoot(file)
  297.     if (total > 10)
  298.        offset = offset + BinaryPokeStr(menufile,offset, strcat("_More Macros",CRLF))
  299.        indent = @TRUE
  300.        total = 1
  301.     endif
  302.     if indent
  303.        if separator
  304.           offset = offset + BinaryPokeStr(menufile,offset, strcat(" _%name%",CRLF))
  305.        else
  306.           offset = offset + BinaryPokeStr(menufile,offset, strcat(" %name%",CRLF))
  307.        endif
  308.       total=1
  309.     else 
  310.        if separator
  311.           offset = offset + BinaryPokeStr(menufile,offset, strcat("_%name%",CRLF))
  312.        else
  313.           offset = offset + BinaryPokeStr(menufile,offset, strcat("%name%",CRLF))
  314.        endif
  315.     endif
  316.     separator = @FALSE
  317.     if strlen(DirName) > 0
  318.        name = strcat(path,"\%DirName%\")
  319.     else
  320.        name = strcat(path,"\")
  321.     endif
  322.     fullname = strcat(name,file)
  323.     offset = offset + BinaryPokeStr(menufile,offset, strcat('       if FileExist("%fullname%")',CRLF))
  324.     offset = offset + BinaryPokeStr(menufile,offset, strcat('          call("%fullname%","")',CRLF))
  325.     offset = offset + BinaryPokeStr(menufile,offset, strcat('       endif',CRLF))
  326.     offset = offset + BinaryPokeStr(menufile,offset, CRLF)
  327.     index = index+1
  328.     total = total+1
  329. endwhile
  330. offset = offset + BinaryPokeStr(menufile,offset,CRLF)
  331. Drop(index,file,name,fullname,total)
  332. return
  333.  
  334.  
  335. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  336. Exit      ; Put an exit here in case anyone ever drops through to cancel
  337.           ; Not that we would ever do anything like that ourselves...
  338. :CANCEL
  339.        %CancelCmd%
  340.